library FCWidgetUtils;

import 'package:flutter/material.dart';
import 'dart:math' as math;
import 'package:wgq_dart/wgq_dart.dart';
import 'package:wgq_flutter/wgq_flutter.dart';

enum FutureViewType{
	noData,
	error,
}


class WFWidgetUtils {
	/// 生成一个随机颜色
	static Color sjColor() {
		math.Random random = math.Random();
		return Color.fromARGB(255, random.nextInt(255), random.nextInt(255), random.nextInt(255));
	}

	/// 根据样式,计算出文本的宽度
	static double calculateTextWidth(TextStyle style,String text){
		if (WDDataType.isAir(text) || style==null){
			return 0;
		}
		final textPainter = TextPainter(
			textDirection: TextDirection.ltr,
			text: TextSpan(
				text: text,
				style: style,
			),
		);
		textPainter.layout();
		return textPainter.width;
	}

	static Widget noDataWidget({bool isNetError=false,Color bgColor=Colors.white,Color mainColor=const Color(0xff999999)}){

		IconData icon = isNetError?Icons.signal_wifi_off:Icons.inbox;
		String hitString = isNetError?"网络连接失败":"未找到相关数据";

		return Material(
			child: Center(
				child: Container(
					color: bgColor,
					child: Row(
						mainAxisAlignment: MainAxisAlignment.center,
						children: [
							Column(
								mainAxisAlignment: MainAxisAlignment.center,
								children: <Widget>[
									Icon(
										icon,
										color: mainColor,
										size: 64,
									),
									Padding(
										padding: const EdgeInsets.only(top: 16.0),
										child: Text(
											hitString,
											style: TextStyle(color: mainColor, fontSize: 14),
										),
									),
								],
							),
						],
					),
				),
			),
		);
	}

	static Widget buildFutureView({
		required VoidCallback cb,
		required FutureViewType type,
		Widget? image,
		Text? text
	}){
		image ??= Icon(type==FutureViewType.noData?Icons.inbox:Icons.error,size: 64,);
		text ??= Text(type==FutureViewType.noData?"暂无数据!":"出错了,请稍后再试!",style: const TextStyle(
				fontSize: 18
		),);
		return Center(
			child: WFImageButton(
				image,
				text,
				onClick: (int,str){
					cb();
				},
			),
		);
	}

	// static Widget buildNoDataView(VoidCallback cb){
	// 	return Center(
	// 		child: WFImageButton(
	// 			const Icon(Icons.inbox,size: 64,),
	// 			const Text("暂无数据!",style: TextStyle(
	// 				fontSize: 18
	// 			),),
	// 			onClick: (int,str){
	// 				cb();
	// 			},
	// 		),
	// 	);
	// }
	//
	// static Widget buildErrorView(VoidCallback cb){
	// 	return Center(
	// 		child: WFImageButton(
	// 			const Icon(Icons.error,size: 64,),
	// 			const Text("出错了,请稍后再试!",style: TextStyle(
	// 					fontSize: 18
	// 			),),
	// 			onClick: (int,str){
	// 				cb();
	// 			},
	// 		),
	// 	);
	// }


}





//class NetImageWithCorner extends StatelessWidget {
//	final String imageUrl;
//	final double radius;
//	final Size size;
//
//	NetImageWithCorner({this.imageUrl, this.radius, this.size});
//
//	@override
//	Widget build(BuildContext context) {
//		Size aSize = size ?? Size(double.infinity, double.infinity);
//		var aRadius = radius ?? 4.0;
//		return ClipRRect(
//			borderRadius: BorderRadius.circular(aRadius),
//			child: new CachedNetworkImage(
//				imageUrl: imageUrl,
//				fit: BoxFit.cover,
//				height: aSize.height,
//				width: aSize.width,
//			),
//		);
//	}
//}





